package com.bangdream.michelia.view.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bangdream.michelia.R;
import com.bangdream.michelia.entity.MessageBean;

import java.util.ArrayList;
import java.util.List;

/**
 * @date on 2018/8/10 23:42
 * @email 909732184@qq.com
 * 我的消息列表适配器
 */
public class MyMessageListAdapter extends RecyclerView.Adapter {
    private Context context;
    private LayoutInflater layoutInflater;
    private List<MessageBean> data = new ArrayList<>();
    private OnItemClickListener onItemClickListener;

    public List<MessageBean> getData() {
        return data;
    }

    public void setData(List<MessageBean> data) {
        this.data = data;
    }

    public OnItemClickListener getOnItemClickListener() {
        return onItemClickListener;
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener{
        void onMessageItemClick(int position);
    }
    public MyMessageListAdapter(Context context) {
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = layoutInflater.inflate(R.layout.my_message_list_item,parent,false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.position = position;
    }

    @Override
    public int getItemCount() {
        return data==null?0:data.size();
//        return 5;
    }

    class ViewHolder extends RecyclerView.ViewHolder{
        private int position;
        private TextView tvNumber;
        private TextView tvMoney;
        private TextView tvTitle;
        private TextView tvStudyNumber;
        private TextView tvTime;
        private ImageView ivLogo;
        public ViewHolder(View itemView) {
            super(itemView);
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(onItemClickListener!=null){
                        onItemClickListener.onMessageItemClick(position);
                    }
                }
            });
        }
    }
}
